import request, { ApiResponse } from '@/utils/service/request'
import {
  AddClassifyReq,
  BindClassifyReq,
  ClassifyItem,
  EditClassifyReq,
  GetClassifyTreeReq,
} from './model/classifyModel'

export enum ClassifyApi {
  /** 获取分类树 */
  GET_CLASSIFY_TREE = '/paixin-admin/category/getTree',
  /** 添加分类 */
  ADD_CLASSIFY = '/paixin-admin/category/save',
  /** 删除分类 */
  DELETE_CLASSIFY = '/paixin-admin/category/remove',
  /** 编辑分类 */
  EDIT_CLASSIFY = '/paixin-admin/category/update',
  /** 分类绑定图集标签 */
  BIND_CLASSIFY = '/paixin-admin/category/ref',

}

export function fetchClassify(body: GetClassifyTreeReq = { parentId: '0' }) {
  return request.post<ApiResponse<ClassifyItem>>(
    ClassifyApi.GET_CLASSIFY_TREE,
    body
  )
}

export function addClassify(body: AddClassifyReq) {
  return request.post<ApiResponse<null>>(ClassifyApi.ADD_CLASSIFY, body)
}

export function deleteClassify(id: string) {
  return request.delete<ApiResponse<null>>(ClassifyApi.DELETE_CLASSIFY, {
    params: {
      id,
    },
  })
}

export function editClassify(body: EditClassifyReq) {
  return request.post<ApiResponse<null>>(ClassifyApi.EDIT_CLASSIFY, body)
}

export function bindCategory(body: BindClassifyReq) {
  return request.post<ApiResponse<null>>(ClassifyApi.BIND_CLASSIFY, body)
}


